package controllers;


import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import models.User;
import asg.cliche.Command;
import asg.cliche.Param;
import asg.cliche.Shell;
import asg.cliche.ShellFactory;

import com.google.common.base.Optional;

public class Main
{
  PacemakerAPI paceApi = new PacemakerAPI();
  private Map<String, User> users = new HashMap<String, User>();
  
  @Command(description="Create a new User")
  public User createUser(String firstName, String lastName, String email, String password) 
  {
    User user = new User (firstName, lastName, email, password);
    users.put(email, user);
    return user;
  }

  @Command(description="Create a new User")
  public User getUser(String email) 
  {
    return users.get(email);
  }

  @Command(description="Create a new User")
  public Collection<User> getUsers ()
  {
    return users.values();
  }

  @Command(description="Delete a User")
  public void deleteUser (@Param(name="email") String email)
  {
    Optional<User> user = Optional.fromNullable(paceApi.getUserByEmail(email));
    if (user.isPresent())
    {
      paceApi.deleteUser(user.get().id);
    }
  }

  
  public static void main(String[] args) throws IOException
  {
    Shell shell = ShellFactory.createConsoleShell("pc", "Welcome to pcemaker-console - ?help for instructions", new Main());
    shell.commandLoop(); 
  }
  
}